home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / fscompr / zlib.h < prev    next >
C/C++ Source or Header  |  1996-07-24  |  37KB  |  781 lines

  1. /* zlib.h -- interface of the 'zlib' general purpose compression library
  2.   version 1.0.4, Jul 24th, 1996.
  3.  
  4.   Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler
  5.  
  6.   This software is provided 'as-is', without any express or implied
  7.   warranty.  In no event will the authors be held liable for any damages
  8.   arising from the use of this software.
  9.  
  10.   Permission is granted to anyone to use this software for any purpose,
  11.   including commercial applications, and to alter it and redistribute it
  12.   freely, subject to the following restrictions:
  13.  
  14.   1. The origin of this software must not be misrepresented; you must not
  15.      claim that you wrote the original software. If you use this software
  16.      in a product, an acknowledgment in the product documentation would be
  17.      appreciated but is not required.
  18.   2. Altered source versions must be plainly marked as such, and must not be
  19.      misrepresented as being the original software.
  20.   3. This notice may not be removed or altered from any source distribution.
  21.  
  22.   Jean-loup Gailly        Mark Adler
  23.   gzip@prep.ai.mit.edu    madler@alumni.caltech.edu
  24.  
  25.  
  26.   The data format used by the zlib library is described by RFCs (Request for
  27.   Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
  28.   (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
  29. */
  30.  
  31. #ifndef _ZLIB_H
  32. #define _ZLIB_H
  33.  
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. #include "zconf.h"
  39.  
  40. #define ZLIB_VERSION "1.0.4"
  41.  
  42. /* 
  43.      The 'zlib' compression library provides in-memory compression and
  44.   decompression functions, including integrity checks of the uncompressed
  45.   data.  This version of the library supports only one compression method
  46.   (deflation) but other algorithms may be added later and will have the same
  47.   stream interface.
  48.  
  49.      For compression the application must provide the output buffer and
  50.   may optionally provide the input buffer for optimization. For decompression,
  51.   the application must provide the input buffer and may optionally provide
  52.   the output buffer for optimization.
  53.  
  54.      Compression can be done in a single step if the buffers are large
  55.   enough (for example if an input file is mmap'ed), or can be done by
  56.   repeated calls of the compression function.  In the latter case, the
  57.   application must provide more input and/or consume the output
  58.   (providing more output space) before each call.
  59.  
  60.      The library does not install any signal handler. It is recommended to
  61.   add at least a handler for SIGSEGV when decompressing; the library checks
  62.   the consistency of the input data whenever possible but may go nuts
  63.   for some forms of corrupted input.
  64. */
  65.  
  66. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  67. typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
  68.  
  69. struct internal_state;
  70.  
  71. typedef struct z_stream_s {
  72.     Bytef    *next_in;  /* next input byte */
  73.     uInt     avail_in;  /* number of bytes available at next_in */
  74.     uLong    total_in;  /* total nb of input bytes read so far */
  75.  
  76.     Bytef    *next_out; /* next output byte should be put there */
  77.     uInt     avail_out; /* remaining free space at next_out */
  78.     uLong    total_out; /* total nb of bytes output so far */
  79.  
  80.     char     *msg;      /* last error message, NULL if no error */
  81.     struct internal_state FAR *state; /* not visible by applications */
  82.  
  83.     alloc_func zalloc;  /* used to allocate the internal state */
  84.     free_func  zfree;   /* used to free the internal state */
  85.     voidpf     opaque;  /* private data object passed to zalloc and zfree */
  86.  
  87.     int     data_type;  /* best guess about the data type: ascii or binary */
  88.     uLong   adler;      /* adler32 value of the uncompressed data */
  89.     uLong   reserved;   /* reserved for future use */
  90. } z_stream;
  91.  
  92. typedef z_stream FAR *z_streamp;
  93.  
  94. /*
  95.    The application must update next_in and avail_in when avail_in has
  96.    dropped to zero. It must update next_out and avail_out when avail_out
  97.    has dropped to zero. The application must initialize zalloc, zfree and
  98.    opaque before calling the init function. All other fields are set by the
  99.    compression library and must not be updated by the application.
  100.  
  101.    The opaque value provided by the application will be passed as the first
  102.    parameter for calls of zalloc and zfree. This can be useful for custom
  103.    memory management. The compression library attaches no meaning to the
  104.    opaque value.
  105.  
  106.    zalloc must return Z_NULL if there is not enough memory for the object.
  107.    On 16-bit systems, the functions zalloc and zfree must be able to allocate
  108.    exactly 65536 bytes, but will not be required to allocate more than this
  109.    if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
  110.    pointers returned by zalloc for objects of exactly 65536 bytes *must*
  111.    have their offset normalized to zero. The default allocation function
  112.    provided by this library ensures this (see zutil.c). To reduce memory
  113.    requirements and avoid any allocation of 64K objects, at the expense of
  114.    compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
  115.  
  116.    The fields total_in and total_out can be used for statistics or
  117.    progress reports. After compression, total_in holds the total size of
  118.    the uncompressed data and may be saved for use in the decompressor
  119.    (particularly if the decompressor wants to decompress everything in
  120.    a single step).
  121. */
  122.  
  123.                         /* constants */
  124.  
  125. #define Z_NO_FLUSH      0
  126. #define Z_PARTIAL_FLUSH 1
  127. #define Z_SYNC_FLUSH    2
  128. #define Z_FULL_FLUSH    3
  129. #define Z_FINISH        4
  130. /* Allowed flush values; see deflate() below for details */
  131.  
  132. #define Z_OK            0
  133. #define Z_STREAM_END    1
  134. #define Z_NEED_DICT     2
  135. #define Z_ERRNO        (-1)
  136. #define Z_STREAM_ERROR (-2)
  137. #define Z_DATA_ERROR   (-3)
  138. #define Z_MEM_ERROR    (-4)
  139. #define Z_BUF_ERROR    (-5)
  140. #define Z_VERSION_ERROR (-6)
  141. /* Return codes for the compression/decompression functions. Negative
  142.  * values are errors, positive values are used for special but normal events.
  143.  */
  144.  
  145. #define Z_NO_COMPRESSION         0
  146. #define Z_BEST_SPEED             1
  147. #define Z_BEST_COMPRESSION       9
  148. #define Z_DEFAULT_COMPRESSION  (-1)
  149. /* compression levels */
  150.  
  151. #define Z_FILTERED            1
  152. #define Z_HUFFMAN_ONLY        2
  153. #define Z_DEFAULT_STRATEGY    0
  154. /* compression strategy; see deflateInit2() below for details */
  155.  
  156. #define Z_BINARY   0
  157. #define Z_ASCII    1
  158. #define Z_UNKNOWN  2
  159. /* Possible values of the data_type field */
  160.  
  161. #define Z_DEFLATED   8
  162. /* The deflate compression method (the only one supported in this version) */
  163.  
  164. #define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
  165.  
  166. #define zlib_version zlibVersion()
  167. /* for compatibility with versions < 1.0.2 */
  168.  
  169.                         /* basic functions */
  170.  
  171. extern const char * EXPORT zlibVersion OF((void));
  172. /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
  173.    If the first character differs, the library code actually used is
  174.    not compatible with the zlib.h header file used by the application.
  175.    This check is automatically made by deflateInit and inflateInit.
  176.  */
  177.  
  178. /* 
  179. extern int EXPORT deflateInit OF((z_streamp strm, int level));
  180.  
  181.      Initializes the internal stream state for compression. The fields
  182.    zalloc, zfree and opaque must be initialized before by the caller.
  183.    If zalloc and zfree are set to Z_NULL, deflateInit updates them to
  184.    use default allocation functions.
  185.  
  186.      The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
  187.    1 gives best speed, 9 gives best compression, 0 gives no compression at
  188.    all (the input data is simply copied a block at a time).
  189.    Z_DEFAULT_COMPRESSION requests a default compromise between speed and
  190.    compression (currently equivalent to level 6).
  191.  
  192.      deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
  193.    enough memory, Z_STREAM_ERROR if level is not a valid compression level,
  194.    Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
  195.    with the version assumed by the